import {
  mapGetters
} from 'vuex'

export default {
  computed: {
    ...mapGetters('m_cart', ['total'])
  },
  watch:{
    total(value){
      if(value>0)this.setBedge()
      else this.removeBedge()
    }
  },
  onShow() {
    // 在页面刚展示的时候，设置数字徽标
    if(this.total>0)this.setBedge()
    else this.removeBedge()
  },
  methods: {
    setBedge() {
      uni.setTabBarBadge({
        index: 2,
        text: this.total + ''
      })
    },
    removeBedge(){
      uni.removeTabBarBadge({
        index:2
      })
    }
  }
}